const cloud = require('wx-server-sdk')
const TcbRouter = require('tcb-router');

cloud.init({
  env: 'cloud1-9g2qt1ex40c305d9'
});

const db = cloud.database();
const _ = db.command;
const $ = _.aggregate;

const getParams = ctx => {
  let params = ctx._req.event;
  delete params.$url;
  return params;
}

const success = data => {
  return {
    status: 200,
    data
  }
}

const fail = data => {
  return {
    ...data
  }
}

exports.main = async (event, context) => {
  const app = new TcbRouter({ event });

  app.router('get_question_list', getQuestionList);

  return app.serve();
}

async function getQuestionList(ctx, next) {
  let questionList = await db.collection('question').get();
  ctx.body = success({
    data: questionList.data
  })
}